package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class Region {
    //推荐
    public static final int STATE_NORMAL = 0;
    public static final int STATE_HOT = 1;
    private Long id;

    private String name; //地区名

    private Region parent; //父地区

    private Integer state = STATE_NORMAL; //状态

    //treeview数据转换
    //region--> {text:xx, tags:xx, nodes:xx}
    public Map<String, Object> toMap(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("text", name);
        //给选中框添加一个样式,+ 加号,节点属性
        map.put("lazyLoad",true);
        if (state == STATE_HOT)
        map.put("tags", new String[]{"推荐"});
        map.put("json",toJsonString());
        return map;
    }

    public String toJsonString(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        if (parent != null){
            map.put("pid",parent.getId());
            map.put("pname",parent.getName());
        }
        map.put("state",state);
        return JSONUtils.toJSONString(map);
    }

}